package com.dykj.fireFighting.web.app;

import com.dykj.fireFighting.api.fire.contractMessage.dto.ContractMessageDto;
import com.dykj.fireFighting.api.fire.contractMessage.entity.ContractMessage;
import com.dykj.fireFighting.api.fire.contractMessage.service.IContractMessageService;
import com.dykj.fireFighting.api.fire.contractMessage.vo.ContractMessagesVo;
import com.dykj.fireFighting.common.core.annotation.AutoLog;
import com.dykj.fireFighting.common.core.api.CommonResult;
import com.dykj.fireFighting.common.core.vo.LoginUserVo;
import com.dykj.fireFighting.common.core.vo.PageVo;
import com.dykj.fireFighting.web.base.shiro.ShiroUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@Api(value = "app 维保合同接口", tags = {"app 维保合同接口"})
@RestController
@RequestMapping("app/contractMessage")
public class AppContractMessageController {

    @DubboReference
    private IContractMessageService iContractMessageService;

    @AutoLog(value = "获取合同列表")
    @ApiOperation(value = "获取合同列表", notes = "获取合同列表")
    @GetMapping("/getList")
    public CommonResult<PageVo<ContractMessagesVo>> queryList(ContractMessageDto contractMessageDto) {
        LoginUserVo loginUserVo = ShiroUtil.getUser();
        if(loginUserVo.getUserType()!=0)
        {
            contractMessageDto.setWeibaoUnitsCode(loginUserVo.getEnterpriseId().toString());
        }
        contractMessageDto.setIsDel("0");
        PageVo<ContractMessagesVo> page = iContractMessageService.queryList(contractMessageDto);
        return CommonResult.success(page);
    }


    @AutoLog(value = "获取快过期合同列表")
    @ApiOperation(value = "获取快过期合同列表", notes = "获取快过期合同列表")
    @GetMapping("/getWillExpireList")
    public CommonResult queryWillExpireList() {
        LoginUserVo loginUserVo = ShiroUtil.getUser();
        String unitId=null;
        Integer type =2;
        if(loginUserVo.getUserType()!=0)
        {
            unitId=(loginUserVo.getEnterpriseId().toString());
        }else{
            type=null;
        }
            List<ContractMessagesVo> list= iContractMessageService.getBeExpireList(unitId,type);
        return CommonResult.success(list);
    }

}
